from PIL import Image, ImageDraw, ImageFont


class Where:
    ROOMIN = "room_in"
    ROOMOUT = "room_out"


def show(peoplename, where: Where, text):
    # 打开两张 RGBA 图像
    background_image = Image.open("prototype.png")
    foreground_image = Image.open(f"{peoplename}.png")

    # 计算前景图像放置在背景图像上方的位置
    x_offset = (background_image.width - foreground_image.width) // 2
    y_offset = 20
    # 创建一个新的 RGBA 图像对象作为结果
    result = Image.new("RGBA", background_image.size)

    # 将前景图像粘贴到结果图像上
    result.paste(Image.open(where + ".png").resize((background_image.height, background_image.width)), (0, 0))
    result.paste(foreground_image, (x_offset, y_offset), mask=foreground_image)

    # 将背景图像粘贴到结果图像上
    result.paste(background_image, (0, 0), mask=background_image)
    # 创建画布并绘制图形或文本
    draw = ImageDraw.Draw(result)

    # 字体的加载
    font = ImageFont.truetype("FZSTK.TTF", 24)  # 加载字体
    w, h = draw.textsize(text, font)
    draw.text(((result.width - w) / 2, 143), text, fill="blue", font=font)  # 绘制文本

    # 展示合并后的图像
    result.show()


show(peoplename="people", where=Where.ROOMIN, text="你好")
